#pragma once

struct EMutex
{
	enum Name
	{
	    Count
	};
};


#define CSDL_FPS_HISTORY_SIZE 1

class CSdl final :
	public IEngMod
{
public:
	CSdl();
	~CSdl();

	/*-EngMod-------------------------------------------------------------------*/
	virtual void OnLoop(uint i) override;

	/*--------------------------------------------------------------------------*/

	uint GetFrameNumber() const;
	uint GetAverageFps() const;
	uint GetCurrentSecondFps() const;

	uint GetTicks() const;
	float GetDeltaTime() const;

	std::list<SDL_Event>& GetEvents();

	void SetWindowTitle(const std::string& title);
	const std::string& GetWindowTitle() const;

	void SwapBuffers();

	/*--------------------------------------------------------------------------*/

	void Delay(uint ms);
private:
	void InitMutexes();
	void CreateSdlWindow();

	void CountFrame();		//!< do kopniecia co klatke. zlicza fpsy
	void ProcessEvents();	//!< do kopniecia co klatke = mieli eventy

	uint		m_frameNumber;

	std::string	m_windowTitle;
	/*----------------------------------------------------------------------*/
	SDL_Surface* m_screenSdl;				//!<Ekran SDLowski. Nie dotykać.
	SDL_mutex**	m_mutexes;
	/*----------------------------------------------------------------------*/
	uint		m_averageFps;

	uint		m_fpsHistory[CSDL_FPS_HISTORY_SIZE];	//!<Ilość FPS w ostatniej sekundzie

	uint		m_currentSecondFpsCount;			//!<Zliczanie FPS w aktualnej sekundzie
	ulong		m_fpsCounterTimer;			//!<Licznik czasu (żeby sekundę nazbierać)

	/*----------------------------------------------------------------------*/
	uint		m_sdlTicks;				//!<Optymalizacja SDL_GetTicks()

	/*----------------------------------------------------------------------*/
	float m_deltaTime;
	Timer m_timerForDeltaTime;

	/*----------------------------------------------------------------------*/
	std::list<SDL_Event> m_sdlEventsList;	//!<eventy sdla
};

namespace sh
{
int getticks();
float getdeltatime();
uint getframenumber();
uint getfps();
};

extern CSdl* g_Sdl;